package com.gitee.Transformation

import org.apache.flink.api.scala.{DataSet, ExecutionEnvironment}
import org.apache.flink.api.scala._
import scala.collection.mutable
import scala.util.Random

/*
笛卡尔积
 */
object CorssTest {
  def main(args: Array[String]): Unit = {
    val env: ExecutionEnvironment = ExecutionEnvironment.getExecutionEnvironment
    env.setParallelism(1)
    //Cross 交叉操作/笛卡尔积
    val students = new mutable.MutableList[(Int, String)]
    //学生
    students.+=((1, "张三"))
    students.+=((2, "李四"))
    students.+=((3, "王五"))
    students.+=((4, "赵六"))
    val subjects = new mutable.MutableList[(Int, String)]
    //课程
    subjects.+=((1, "Java"))
    subjects.+=((2, "Python"))
    subjects.+=((3, "前端"))
    subjects.+=((4, "大数据"))
    val input1: DataSet[(Int, String)] = env.fromCollection(Random.shuffle(students))
    val input2: DataSet[(Int, String)] = env.fromCollection(Random.shuffle(subjects))

    input1.cross(input2) { (t1, t2) => {
      (t1._2, t2._2)
    }
    }.print()
  }

}
